xml to object php

70

xml to object php -

$object = json_decode(json_encode(simplexml_load_string($xml)));

php object to xml -

<?php
$array = array('hello' => 'world', 'good' => 'morning');

$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><foo />");
foreach ($array as $k=>$v) {
  $xml->addChild($k, $v);
}
?>

Comments

Submit
0 Comments